﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace CPPEI.Coolzon.Event.UI
{
    /// <summary>
    /// 网络状态的反馈信息事件
    /// </summary>
    public class UINetConnectionStateFeedbackEvent: UIEvent
    {
        public NetConnectionState[] States { get; private set; }

        public bool IsConnected()
        {
            for (int index = 0; index < States.Length; index++)
            {
                if (States[index].IsConnected)
                {
                    return true;
                }
            }
            return false;
        }

        public UINetConnectionStateFeedbackEvent(List<NetConnectionState> states)
        {
            States = states.ToArray();
        }

        public class NetConnectionState
        {
            public string IP { get; private set; }
            public int Port { get; private set; }

            /// <summary>
            /// 是否处于连接状态
            /// </summary>
            public bool IsConnected { get; private set; }

            public NetConnectionState(string ip, int port, bool isConnected)
            {
                this.IP = ip;
                this.Port = port;
                this.IsConnected = isConnected;
            }
        }
    }
}
